﻿using PARK.Common.Const;
using SqlSugar;
using System;
using Yitter.IdGenerator;

namespace PARK.Consumer.Entity
{
    /// <summary>
    /// 餐段维护
    /// </summary>
    [SugarTable("consum_timeInterval")]
    [Tenant(ClaimConst.TENANT_ID)]
    public class ConsumtimeIntervalEntity
    {
        /// <summary>
        /// 
        /// </summary>
        [SugarColumn(ColumnName = "Id", IsPrimaryKey = true)]
        public string Id { get; set; }
        /// <summary>
        /// 餐段名称
        /// </summary>
        [SugarColumn(ColumnName = "TimeIntervalName")]
        public string TimeIntervalName { get; set; }
        /// <summary>
        /// 开始时间
        /// </summary>
        [SugarColumn(ColumnName = "TimeBeg")]
        public string TimeBeg { get; set; }        
        /// <summary>
        /// 结束时间
        /// </summary>
        [SugarColumn(ColumnName = "TimeEnd")]        
        public string TimeEnd { get; set; }
             
        /// <summary>
        /// 备注
        /// </summary>
        [SugarColumn(ColumnName = "Description")]        
        public string Description { get; set; }
        /// <summary>
        /// LastModifyUserId
        /// </summary>
        [SugarColumn(ColumnName = "LastModifyUserId")]        
        public string LastModifyUserId { get; set; }
        /// <summary>
        /// LastModifyUserName
        /// </summary>
        [SugarColumn(ColumnName = "LastModifyUserName")]        
        public string LastModifyUserName { get; set; }
        /// <summary>
        /// LastModifyTime
        /// </summary>
        [SugarColumn(ColumnName = "LastModifyTime")]        
        public DateTime? LastModifyTime { get; set; }        
        /// <summary>
        /// 
        /// </summary>
        [SugarColumn(ColumnName = "dbDate")]        
        public DateTime? DbDate { get; set; }

        /// <summary>
        /// 所属公司Id
        /// </summary>
        [SugarColumn(ColumnName = "CompanyId")]
        public string CompanyId { get; set; }

        /// <summary>
        /// 公司名称
        /// </summary>
        [SugarColumn(ColumnName = "CompanyName")]
        public string CompanyName { get; set; }

        /// <summary>
        /// 创建人Id
        /// </summary>
        [SugarColumn(ColumnName = "CreatorUserId")]
        public string CreatorUserId { get; set; }

        /// <summary>
        /// 创建人姓名
        /// </summary>
        [SugarColumn(ColumnName = "CreatorUserName")]
        public string CreatorUserName { get; set; }

        /// <summary>
        /// 创建日期
        /// </summary>
        [SugarColumn(ColumnName = "CreatorTime")]
        public DateTime? CreatorTime { get; set; }

        /// <summary>
        /// 创建
        /// </summary>
        public virtual void Create()
        {
            var userId = App.User.FindFirst(ClaimConst.CLAINM_USERID)?.Value;
            var userName = App.User.FindFirst(ClaimConst.CLAINM_REALNAME)?.Value;
            this.Id = YitIdHelper.NextId().ToString();
            this.CreatorTime = DateTime.Now;
            if (!string.IsNullOrEmpty(userId))
            {
                this.CreatorUserId = CreatorUserId == null ? userId : CreatorUserId;
                this.CreatorUserName = CreatorUserName == null ? userName : CreatorUserName;
            }
        }
        /// <summary>
        /// 修改
        /// </summary>
        public virtual void LastModify(string Id)
        {
            this.Id = Id;
            var userId = App.User.FindFirst(ClaimConst.CLAINM_USERID)?.Value;
            var userName = App.User.FindFirst(ClaimConst.CLAINM_REALNAME)?.Value;
            this.LastModifyTime = DateTime.Now;
            if (!string.IsNullOrEmpty(userId))
            {
                this.LastModifyUserId = userId;
                this.LastModifyUserName = userName;
            }
        }
    }
}